<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <input type="text" style="width: 500px;" /><br />
  <button>提交</button>
  <script>
    var input = document.querySelector('input')
    var btn = document.querySelector('button')
    input.oninput = function () {
      var val = input.value
      var xhr = new XMLHttpRequest()
      xhr.open('GET', `https://apis.tianapi.com/charconvert/index?key=1abddedd769e196b38ba149d49817d13&text=${val}`)
      xhr.send()
      xhr.onreadystatechange = function (res) {
        if (xhr.readyState == 4 && xhr.status == 200) {
          var obj = JSON.parse(xhr.responseText)
          console.log(obj)
          btn.onclick = function () {
            alert('转换成繁体字为： ' + obj.result.outtext)
          }
        }
      }
    }


  </script>
</body>

</html>